package birdry.ui.components.button
{
	import birdry.ui.components.button.BasicButton;
	import birdry.utils.MovieClipUtil;
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;
	import flash.display.MovieClip;
	
	/**
	 * ...
	 * @author 
	 */
	public class  MotionButton extends BasicButton	{
		
		private var _listener:Function;
		
		public function MotionButton(view:DisplayObject, listener:Function, hit:DisplayObject = null): void	{
			super( view, hit );
			_listener = listener;
			addEvent();
		}
		
		private function removeEvent():void 		{
			view.removeEventListener( MouseEvent.MOUSE_OVER, onMouseOver);
			view.removeEventListener( MouseEvent.MOUSE_OUT, onMouseOut);
			view.removeEventListener( MouseEvent.CLICK, onClick);
		}
		
		private function addEvent():void 		{
			view.addEventListener( MouseEvent.MOUSE_OVER, onMouseOver);
			view.addEventListener( MouseEvent.MOUSE_OUT, onMouseOut);
			view.addEventListener( MouseEvent.CLICK, onClick);
		}
		
		private function onMouseOver(e:MouseEvent):void 		{
			MovieClipUtil.gotoFrame( MovieClip(view) );
		}
		
		private function onMouseOut(e:MouseEvent):void 		{
			MovieClipUtil.gotoFrame( MovieClip(view), 1);
		}
		
		private function onClick(e:MouseEvent):void 		{
			_listener(e);
		}
		
	}
	
}